﻿using System.Collections.Generic;
using System.Linq;

namespace Uber.Core.Model
{
    public static class Tools
    {
        public static object ForNull(this object o, object v)
        {
            return o ?? v;
        }

        public static string And(this string s, string s1)
        {
            return s + ", " + s1;
        }

        public static char ToTip(string role)
        {
            return role[0];
        }
    }

    public static class Extensions
    {
        public static IEnumerable<string> GetRecipients(this string s)
        {
            if (string.IsNullOrWhiteSpace(s) || !s.Trim().StartsWith("@")) return new string[] { };
            s = s.Trim(' ', '@');
            if (s.IndexOf(' ') == -1) return new[]{s};
            var w = s.Substring(0, s.IndexOf(' '));

            return GetRecipients(s.Substring(w.Length)).Concat(new[] { w });
        }
    }
}